<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>登陆</title>
    <meta name="description" content="particles.js is a lightweight JavaScript library for creating particles.">
    <meta name="author" content="Vincent Garreau"/>
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link rel="stylesheet" media="screen" href="/static/util/login/css/style.css">
    <link rel="stylesheet" type="text/css" href="/static/util/login/css/reset.css"/>
</head>
<body>

<div id="particles-js">
    <div class="login">
        <div class="login-top">
            登录
        </div>
        <div class="login-center clearfix">
            <div class="login-center-img"><img src="/static/util/login/img/name.png"/></div>
            <div class="login-center-input">
                <input type="text" name="username" value="" placeholder="请输入您的用户名" onfocus="this.placeholder=''"
                       onblur="this.placeholder='请输入您的用户名'"/>
                <div class="login-center-input-text">用户名</div>
            </div>
        </div>
        <div class="login-center clearfix">
            <div class="login-center-img"><img src="/static/util/login/img/password.png"/></div>
            <div class="login-center-input">
                <input type="password" name="password" value="" placeholder="请输入您的密码" onfocus="this.placeholder=''"
                       onblur="this.placeholder='请输入您的密码'"/>
                <div class="login-center-input-text">密码</div>
            </div>
        </div>
        <div class="login-button">
            登录
        </div>
    </div>
    <div class="sk-rotating-plane"></div>
</div>

<!-- scripts -->
<script src="/static/util/login/js/particles.min.js"></script>
<script src="/static/util/login/js/app.js"></script>

<script src="/static/util/layui-v2.5.5/layui.js"></script>
<script src="/static/js/global-var.js"></script>
<script src="/static/js/index.js"></script>

<script type="text/javascript">
    let index = setInterval(function () {
        if ($ && layer) {
            $('input[name=username]').val(getCache('username'));
            $('input[name=password]').val(getCache('password'));

            document.querySelector(".login-button").onclick = function () {
                setCache('username', $('input[name=username]').val());
                setCache('password', $('input[name=password]').val());

                reqPost(URL_SERVER_ROOT + '/login', {
                    username: $('input[name=username]').val(),
                    password: $('input[name=password]').val(),
                }, function (res) {
                    if (res.code == 0) {
                        setTimeout(function () {
                            gotoUrl(res);
                        }, 200);
                    } else {
                        alert(res.msg)
                    }
                });
            }

            clearInterval(index);
        }
    });

    function gotoUrl(res) {
        let param = getUrlParam(window.location.search);
        if (param && param['redirect']) {
            // getTextReqPath(param['redirect']);
            window.location.href = getTextReqPath(param['redirect']);
        } else {
            // getTextReqPath('/admin/index.html');
            window.location.href = getTextReqPath('/admin/index.html');
        }
    }
</script>
</body>
</html>